package com.xysl.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.xysl.api.domain.UserCustomizeOption;
import com.xysl.api.domain.XyslUser;
import com.xysl.api.model.XyslLoginUser;
import com.xysl.domain.dto.QueryUserCustomizeDTO;
import com.xysl.domain.vo.UserCustomizeVo;
import com.xysl.service.IUserCustomizeOptionService;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 用户自定义配置类型Controller
 *
 * @author xysl
 * @date 2025-01-23
 */
@RequestMapping("/customizeOption")
@Tag(name = "xysl_用户自定义配置",description ="xysl_用户自定义配置")
@RestController
public class UserCustomizeOptionController extends BaseController
{
    @Resource
    private IUserCustomizeOptionService userCustomizeOptionService;


    @Operation(summary = "获取自定义配置选项")
    @PostMapping("/list")
    public R<List<UserCustomizeVo>> list(@RequestBody QueryUserCustomizeDTO param)
    {
        XyslLoginUser xyslLoginUser = SecurityUtils.getXyslLoginUser();
        XyslUser user = xyslLoginUser.getXyslUser();
        param.setUserId(user.getId());
        List<UserCustomizeVo> list = userCustomizeOptionService.selectUserCustomizeList(param);
        return R.ok(list);
    }


    @Operation(summary = "用户调整展示选项")
    @PostMapping("/userCustomizeConfig")
    public R userCustomizeConfig(@RequestBody QueryUserCustomizeDTO param)
    {
        XyslLoginUser xyslLoginUser = SecurityUtils.getXyslLoginUser();
        XyslUser user = xyslLoginUser.getXyslUser();
        param.setUserId(user.getId());
        return userCustomizeOptionService.userCustomizeConfig(param);
    }



    /**
     * 获取用户自定义配置类型详细信息
     */
    @Hidden
    @RequiresPermissions("enroll:option:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userCustomizeOptionService.selectUserCustomizeOptionById(id));
    }

    /**
     * 新增用户自定义配置类型
     */
    @Hidden
    @RequiresPermissions("enroll:option:add")
    @Log(title = "用户自定义配置类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserCustomizeOption userCustomizeOption)
    {
        return toAjax(userCustomizeOptionService.insertUserCustomizeOption(userCustomizeOption));
    }

    /**
     * 修改用户自定义配置类型
     */
    @Hidden
    @RequiresPermissions("enroll:option:edit")
    @Log(title = "用户自定义配置类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserCustomizeOption userCustomizeOption)
    {
        return toAjax(userCustomizeOptionService.updateUserCustomizeOption(userCustomizeOption));
    }

    /**
     * 删除用户自定义配置类型
     */
    @Hidden
    @RequiresPermissions("enroll:option:remove")
    @Log(title = "用户自定义配置类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userCustomizeOptionService.deleteUserCustomizeOptionByIds(ids));
    }
}
